package org.edu.modules.jxzy.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.injector.methods.SelectOne;
import org.edu.modules.jxzy.entity.JwCangku;
import org.edu.modules.jxzy.entity.JwJiaocaiKucun;
import org.edu.modules.jxzy.mapper.JwJiaocaiKucunMapper;
import org.edu.modules.jxzy.service.IJwJiaocaiKucunService;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import java.util.List;

/**
 * @Description: 教材库存表
 * @Author: jeecg-boot
 * @Date:   2021-04-14
 * @Version: V1.0
 */
@Service
public class JwJiaocaiKucunServiceImpl extends ServiceImpl<JwJiaocaiKucunMapper, JwJiaocaiKucun> implements IJwJiaocaiKucunService {

    @Override
    public List<JwJiaocaiKucun> getByJcid(Integer jcid) {
        return baseMapper.selectList(new QueryWrapper<JwJiaocaiKucun>().eq("jcid",jcid));
    }

    @Override
    public JwJiaocaiKucun getBy2id(Integer jcid, Integer ckid){
        return baseMapper.selectOne(new QueryWrapper<JwJiaocaiKucun>()
                .eq("jcid",jcid)
                .eq("ckid",ckid));
    }

    @Override
    public int calcCount(Integer jcid) {
        QueryWrapper<JwJiaocaiKucun> wrapper = new QueryWrapper<>();
        wrapper.select("sum(num) as num");
        wrapper.eq("jcid", jcid);
        JwJiaocaiKucun temp = this.getOne(wrapper);
        return temp == null ? 0 : temp.getNum();
    }


}
